package com.ruoyi.epidemic.task;

import com.ruoyi.epidemic.domain.TbDetails;
import com.ruoyi.epidemic.domain.TbHistory;
import com.ruoyi.epidemic.service.ITbDetailsService;
import com.ruoyi.epidemic.service.ITbHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zyc
 * @createDate 2023/3/22 10:48
 */
@Component("dataTask")
public class DataTask {
    @Autowired
    ITbHistoryService historyService;
    @Autowired
    ITbDetailsService detailsService;
    //定时保存数据统计
    public void ryNoParams()
    {
        //当下的统计数据
        TbHistory tbHistory = detailsService.selectTbDetailsCount();
        tbHistory.setCreateDate(new Date());
        //最新的统计数据
        TbHistory newHistory = historyService.selectNewData();
        System.out.println(newHistory);
        if (newHistory!=null){
            tbHistory.setConfirmAdd(tbHistory.getConfirm()-newHistory.getConfirm());
            tbHistory.setDeadAdd(tbHistory.getDead()-newHistory.getDead());
            tbHistory.setHealAdd(tbHistory.getHeal()-newHistory.getHeal()) ;
            tbHistory.setOverseasAdd(tbHistory.getOverseas()-newHistory.getOverseas());
            tbHistory.setAsymptomaticAdd(tbHistory.getAsymptomatic()-newHistory.getAsymptomatic());
        }
        historyService.insertTbHistory(tbHistory);
        System.out.println("数据统计定时任务执行成功");
    }
}
